﻿namespace TestTool.Tests.Definitions.Data
{
    using System;
    using System.Net;
    using System.Net.NetworkInformation;
    using System.Runtime.CompilerServices;

    public class NetworkInterfaceDescription
    {
        public NetworkInterfaceDescription(NetworkInterface adapter, IPAddress ip)
        {
            this.Name = adapter.Name;
            this.Description = adapter.Description;
            this.IP = ip;
            this.Index = adapter.GetIPProperties().GetIPv4Properties().Index;
        }

        public NetworkInterfaceDescription(string name, IPAddress ip)
        {
            this.Name = name;
            this.Description = name;
            this.IP = ip;
        }

        public string ToString(bool hwStyle)
        {
            if (object.Equals(this.IP, IPAddress.Any) || object.Equals(this.IP, IPAddress.IPv6Any))
            {
                return this.Name;
            }
            return string.Format("{0} ({1})", this.IP.ToString(), hwStyle ? this.Description : this.Name);
        }

        public string Description { get; protected set; }

        public int Index { get; protected set; }

        public IPAddress IP { get; protected set; }

        public string Name { get; protected set; }
    }
}

